import request from '@/utils/http'

export class ComponentLibraryService {

  static pages(params:any) {
    return request.post<any>({
      url: '/visual/component/library/pages',
  	  params
    })
  }
  
  static save(data:FormData) {
    return request.post<any>({
      url: '/visual/component/library/save',
      headers: { "Content-Type": "multipart/form-data" },
  	  data
    })   
  }
  
  static delete(id:string) {
    return request.del<any>({
      url: '/visual/component/library/detain/'+id,
    })
  }


  static get(id:string) {
    return request.get<any>({
      url: '/visual/component/library/'+id,
    })
  }

  /**
   * 根据分类获取组件库列表
   * @param category 组件分类
   * @param params 
   * @returns 
   */
  static getComponentListByCategory(category:string,params:any) {
    return request.post<any>({
      url: '/visual/component/library/'+category+'/list',
      params
    })
  }

  /**
   * 组件数据模型列表
   * @param componentId 组件Id
   * @returns 
   */
  static getComponentDataModelList(componentId:string) {
    return request.get<any>({
      url: '/visual/component/data-model/'+componentId+'/list'
    })
  }

    /**
   * 保存组件数据模型
   * @param componentDataModelId 组件Id
   * @param params 组件数据模型
   * @returns 
   */
    static saveComponentDataModel(componentId:string,params:any) {
      return request.post<any>({
        url: '/visual/component/data-model/'+componentId+'/save',
        params
      })
    }

  /**
   * 删除组件数据模型
   * @param componentDataModelId 组件数据模型Id
   * @returns 
   */
  static deleteComponentDataModel(componentDataModelId:string) {
    return request.del<any>({
      url: '/visual/component/data-model/'+componentDataModelId,
    })
  }

  /**
   * 复制组件数据模型
   * @param componentDataModelId 组件数据模型Id
   * @returns 
   */
  static copyComponentDataModel(componentDataModelId:string) {
    return request.get<any>({
      url: '/visual/component/data-model/'+componentDataModelId+'/copy',
    })
  }

  /**
   * 导入组件数据模型
   * @param componentDataModelId 组件Id
   * @param params 组件数据模型
   * @returns 
   */
    static importComponentDataModelParameter(componentId:string,params:any) {
      return request.post<any>({
        url: '/visual/component/data-model/'+componentId+'/import/parameters',
        params
      })
  }
  
  static getComponentDataModels(componentId:string,type:string) {
      return request.get<any>({
        url: '/visual/component/data-model/'+componentId+'/'+type
      })
  }
}
